package com.qr.service.wmyh.impl;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.mapping.ResultMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.krui.helper.db.DBHelper;
import cn.krui.helper.db.DataPage;
import com.qr.bean.wmyh.JbrUserSalesRecordsDetail;
import com.qr.bean.wmyh.JbrUserSalesRecordsDetailView;
import com.qr.controller.WmyhBase;
import com.qr.mapper.wmyh.JbrUserSalesRecordsDetailMapper;
import com.qr.mapper.wmyh.JbrUserSalesRecordsDetailMapperView;
import com.qr.service.wmyh.JbrUserSalesRecordsDetailService;
//import org.apache.dubbo.config.annotation.Service;

/**
 * @author: zc
 * email: zc8023zs@163.com
 * create_time: 2020/8/11 13:03:37
 */
@Service
//@Service(version = "1.0.0",group="dubbo")
public class JbrUserSalesRecordsDetailServiceImpl implements JbrUserSalesRecordsDetailService{
    @Autowired
    private JbrUserSalesRecordsDetailMapper jbrUserSalesRecordsDetailMapper;

    @Autowired
    private JbrUserSalesRecordsDetailMapperView jbrUserSalesRecordsDetailMapperView;
    
    @Autowired
    private DBHelper dbHelper;

    /**
     * 构造查询条件
     */
    private QueryWrapper<JbrUserSalesRecordsDetail> InitWrapper(JbrUserSalesRecordsDetail where){
        QueryWrapper<JbrUserSalesRecordsDetail> whereWrapper = new QueryWrapper<JbrUserSalesRecordsDetail>();
        if(where.getId()!=null){
			whereWrapper.eq("id",where.getId());
		}
        if(where.getAdvance()!=null){
			whereWrapper.eq("advance",where.getAdvance());
		}
        if(where.getOuts()!=null){
			whereWrapper.eq("outs",where.getOuts());
		}
        if(where.getDate()!=null){
			whereWrapper.eq("date",where.getDate());
		}
        if(where.getActual_entry()!=null){
			whereWrapper.eq("actual_entry",where.getActual_entry());
		}
        if(where.getSub_order_id()!=null){
			whereWrapper.eq("sub_order_id",where.getSub_order_id());
		}
        if(where.getSub_order_num()!=null){
			whereWrapper.eq("sub_order_num",where.getSub_order_num());
		}
        if(where.getDesc()!=null){
			whereWrapper.eq("desc",where.getDesc());
		}
        if(where.getUser_id()!=null){
			whereWrapper.eq("user_id",where.getUser_id());
		}
        if(where.getSuperior_one_id()!=null){
			whereWrapper.eq("superior_one_id",where.getSuperior_one_id());
		}
        if(where.getSale_id()!=null){
			whereWrapper.eq("sale_id",where.getSale_id());
		}
        if(where.getAdd_time()!=null){
			whereWrapper.eq("add_time",where.getAdd_time());
		}
        return whereWrapper;
    }

    private QueryWrapper<JbrUserSalesRecordsDetailView> InitWrapperView(JbrUserSalesRecordsDetailView where){
        QueryWrapper<JbrUserSalesRecordsDetailView> whereWrapper = new QueryWrapper<JbrUserSalesRecordsDetailView>();
        if(where.getId()!=null){
			whereWrapper.eq("id",where.getId());
		}
        if(where.getAdvance()!=null){
			whereWrapper.eq("advance",where.getAdvance());
		}
        if(where.getOuts()!=null){
			whereWrapper.eq("outs",where.getOuts());
		}
        if(where.getDate()!=null){
			whereWrapper.eq("date",where.getDate());
		}
        if(where.getActual_entry()!=null){
			whereWrapper.eq("actual_entry",where.getActual_entry());
		}
        if(where.getSub_order_id()!=null){
			whereWrapper.eq("sub_order_id",where.getSub_order_id());
		}
        if(where.getSub_order_num()!=null){
			whereWrapper.eq("sub_order_num",where.getSub_order_num());
		}
        if(where.getDesc()!=null){
			whereWrapper.eq("desc",where.getDesc());
		}
        if(where.getUser_id()!=null){
			whereWrapper.eq("user_id",where.getUser_id());
		}
        if(where.getSuperior_one_id()!=null){
			whereWrapper.eq("superior_one_id",where.getSuperior_one_id());
		}
        if(where.getSale_id()!=null){
			whereWrapper.eq("sale_id",where.getSale_id());
		}
        if(where.getAdd_time()!=null){
			whereWrapper.eq("add_time",where.getAdd_time());
		}
        return whereWrapper;
    }

    /**
     * 销售记录明细新增
     * @param model 销售记录明细实体
     * @return 影响行数
     */
	@Override
    public Integer add(JbrUserSalesRecordsDetail model){
        return jbrUserSalesRecordsDetailMapper.insert(model);
    }

    /**
     * 销售记录明细修改byid
     * @param model 销售记录明细实体
     * @return 影响行数
     */
	@Override
    public Integer update(JbrUserSalesRecordsDetail model) {
        return jbrUserSalesRecordsDetailMapper.updateById(model);
    }

    /**
     * 销售记录明细修改by条件
     * @param model 销售记录明细实体
     * @param where 销售记录明细条件
     * @return 影响行数
     */
	@Override
    public Integer update(JbrUserSalesRecordsDetail model, Wrapper<JbrUserSalesRecordsDetail> where) {
        return jbrUserSalesRecordsDetailMapper.update(model, where);
    }

    /**
     * 销售记录明细修改by条件-自动封装Wrapper
     * @param model 销售记录明细实体
     * @return 影响行数
     */
	@Override
    public Integer update(JbrUserSalesRecordsDetail model, JbrUserSalesRecordsDetail where) {
        Wrapper<JbrUserSalesRecordsDetail> wrapper = InitWrapper(where);
        return update(model, wrapper);
    }

    /**
     * 销售记录明细修改bySQL *version_id = newVersion where version_id = oldVersion
     * @param fields 修改的数据 col1=xx,col2=yy
     * @param where 参数化条件 col1=#{col1}
     * @param params 条件参数 col1=xx
     * @return 影响行数
     */
	@Override
    public Integer update(Map<String, Object> fields, String where, Map<String, Object> params) {
        return dbHelper.update("jbr_user_sales_records_detail", fields, where, params);
    }

    /**
     * 销售记录明细删除byid
     * @param id 销售记录明细主键
     * @return 影响行数
     */
	@Override
    public Integer del(int id) {
        return jbrUserSalesRecordsDetailMapper.deleteById(id);
    }

    /**
     * 销售记录明细删除by条件
     * @param where 销售记录明细条件
     * @return 影响行数
     */
	@Override
    public Integer del(Wrapper<JbrUserSalesRecordsDetail> where) {
        return jbrUserSalesRecordsDetailMapper.delete(where);
    }

    /**
     * 销售记录明细删除by条件-自动封装Wrapper
     * @param where 销售记录明细条件
     * @return 影响行数
     */
    @Override
    public Integer del(JbrUserSalesRecordsDetail where) { 
        Wrapper<JbrUserSalesRecordsDetail> wrapper = InitWrapper(where);
        return del(wrapper);
    }

    /**
     * 销售记录明细批量删除byid
     * @param ids 销售记录明细主键集合
     * @return 影响行数
     */
	@Override
    public Integer del(List<Integer> ids){
        return jbrUserSalesRecordsDetailMapper.deleteBatchIds(ids);
    }

    /**
     * 销售记录明细批量删除bymap条件
     * @param map 销售记录明细map条件
     * @return 影响行数
     */
	@Override
    public Integer del(Map<String,Object> map){
        return jbrUserSalesRecordsDetailMapper.deleteByMap(map);
    }

    /**
     * 销售记录明细详情byid
     * @param id 销售记录明细主键
     * @return 销售记录明细详情
     */
	@Override
    public JbrUserSalesRecordsDetailView info(int id){
        return jbrUserSalesRecordsDetailMapperView.selectById(id);
    }

    /**
     * 销售记录明细详情by条件
     * @param where 销售记录明细条件
     * @return 销售记录明细详情
     */
	@Override
    public JbrUserSalesRecordsDetailView info(Wrapper<JbrUserSalesRecordsDetailView> where){
        return jbrUserSalesRecordsDetailMapperView.selectOne(where);
    }

    /**
     * 销售记录明细详情by条件-自动封装Wrapper
     * @param where 销售记录明细条件
     * @return 销售记录明细详情
     */
	@Override
    public JbrUserSalesRecordsDetailView info(JbrUserSalesRecordsDetailView where) {
        Wrapper<JbrUserSalesRecordsDetailView> wrapper = InitWrapperView(where);
        return info(wrapper);
    }

    /**
     * 销售记录明细详情bySQL
     * @param columns  列名col1,col2,col3^
     * @param where 条件 col1=#{col1}
     * @param params col1:xx
     * @param mappings col1->col1
     * @return
     */
	@Override
    public JbrUserSalesRecordsDetail info(String columns, String where, Map<String, Object> params, ResultMapping mappings) {
        return dbHelper.selectOne(columns, "jbr_user_sales_records_detail", where, params, JbrUserSalesRecordsDetail.class, mappings);
    }

    /**
     * 销售记录明细批量查询byid
     * @param ids 销售记录明细主键集合
     * @return 销售记录明细列表
     */
	@Override
    public List<JbrUserSalesRecordsDetailView> select(List<Integer> ids){
        return jbrUserSalesRecordsDetailMapperView.selectBatchIds(ids);
    }

    /**
     * 销售记录明细批量查询by条件
     * @param where 销售记录明细条件
     * @return 销售记录明细列表
     */
	@Override
    public List<JbrUserSalesRecordsDetailView> select(Wrapper<JbrUserSalesRecordsDetailView> where){
        return jbrUserSalesRecordsDetailMapperView.selectList(where);
    }

    /**
     * 销售记录明细批量查询by条件-自动封装Wrapper
     * @param where 销售记录明细条件
     * @return 销售记录明细列表
     */
    @Override
    public List<JbrUserSalesRecordsDetailView> select(JbrUserSalesRecordsDetailView where) {
        Wrapper<JbrUserSalesRecordsDetailView> wrapper = InitWrapperView(where);		
        return select(wrapper);
    }

    /**
     * 销售记录明细批量查询bymap条件
     * @param map 销售记录明细map条件
     * @return 销售记录明细列表
     */
	@Override
    public List<JbrUserSalesRecordsDetailView> select(Map<String,Object> map){
        return jbrUserSalesRecordsDetailMapperView.selectByMap(map);
    }

    /**
     * 销售记录明细批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
	@Override
    public IPage<JbrUserSalesRecordsDetailView> select(IPage<JbrUserSalesRecordsDetailView> page, Wrapper<JbrUserSalesRecordsDetailView> where){
        return jbrUserSalesRecordsDetailMapperView.selectPage(page, where);
    }

    /**
     * 销售记录明细批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
    @Override
    public IPage<JbrUserSalesRecordsDetailView> select(IPage<JbrUserSalesRecordsDetailView> page, JbrUserSalesRecordsDetailView where) {
		Wrapper<JbrUserSalesRecordsDetailView> wrapper = InitWrapperView(where);		
        return select(page, wrapper);
    }

    /**
     * 销售记录明细查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(Wrapper<JbrUserSalesRecordsDetailView> where){
        return jbrUserSalesRecordsDetailMapperView.selectCount(where);
    }

    /**
     * 销售记录明细查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(JbrUserSalesRecordsDetailView where){
		Wrapper<JbrUserSalesRecordsDetailView> wrapper = InitWrapperView(where);
        return selectCount(wrapper);
    }

    /**
     * 销售记录明细批量查询bySQL条件分页
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param orderBy 排序字段
     * @param params 参数化 col1=xx
     * @param pageNumber 分页页码
     * @param pageSize 每页行数
     * @param mappings 查询列和实体映射
     * @return 分页之后的数据含总行数
     */
	@Override
    public DataPage<JbrUserSalesRecordsDetailView> select(String columns, String where, String orderBy, Map<String, Object> params, int pageNumber, int pageSize, ResultMapping mappings){
        return dbHelper.select(columns, "jbr_user_sales_records_detail", where, orderBy, params, pageNumber, pageSize, JbrUserSalesRecordsDetailView.class,mappings);
    }

    /**
     * 销售记录明细批量查询bySQL条件
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param params 参数化 col1=xx
     * @param mappings 查询列和实体映射
     * @return 栏目扩展列表
     */
	@Override
    public List<JbrUserSalesRecordsDetailView> select(String columns, String where, Map<String, Object> params, ResultMapping mappings){
        return dbHelper.select(columns,"jbr_user_sales_records_detail",where,params,JbrUserSalesRecordsDetailView.class,mappings);
    }
}